#include "Command.h"
#include "./QClientInterface.h"
#include "../QCommon/user.h"
#include <string>
#include <string.h>
#include <vector>
#include <iostream>
using namespace std;

void list()
{
	vector<User> list = getOnlineUsers();
	cout << "***************** User List *****************" << endl;
	cout << "id\tname\tip\t\tpid" << endl;
	for(int i = 0;i<list.size();i++){
		User user = list[i];
		int index = search_user_index(user.ip,user.pid);
		cout << index << "\t" << user.name << "\t" << user.ip << "\t" << user.pid << endl;
	}
	cout << "------------------END OF LIST---------------" << endl;
	cout << "< type your commond ... use 'h' for help>" << endl;
}

void send_message(char* message,int id)
{
	string msg = message;
	User u = search_user(id);
	User* user = &u;
	sendMessage(msg, *user);
	cout << "< type your commond ... use 'h' for help>" << endl;
}

void send_file(char* file_path,int id)
{
	char *ptr=file_path;
	while(*ptr==' ') ptr++;
	char *tail=file_path+strlen(file_path)-1;
	while(*tail==' ') tail--;
	*(tail+1)='\0';	
	string path = ptr;
	User u = search_user(id);
	User *user = &u;
	sendFile(path, *user);
	cout << "< type your commond ... >" << endl;
}
